package org.jeecg.modules.cascv.image.job;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.cascv.image.util.LaptopConstant;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class CacheClearJob {
//    @Scheduled(cron = "0/300 * * * * ? ")
    @Scheduled(fixedRate = 600000) //上一次执行后延迟5分就开始执行
    public void exec() {
        if (LaptopConstant.timeMap.isEmpty()) {
            return;
        }
        List<String> list = new ArrayList<>();
        log.info("清除前数据timeMap" + LaptopConstant.timeMap);
        log.info("清除前数据infoMap" + LaptopConstant.infoMap);
        Map<String, Long> map = LaptopConstant.timeMap;

        Long currentTime = System.currentTimeMillis();

        for (Map.Entry<String, Long> entry : map.entrySet()) {
            if (entry.getValue() <= currentTime) {
                list.add(entry.getKey());
            }
        }

        for (String s : list) {
            LaptopConstant.timeMap.remove(s);
            LaptopConstant.infoMap.remove(s);
            LaptopConstant.threadMap.remove(s);
            LaptopConstant.imageNumMap.remove(s);
            LaptopConstant.packageTotalNum.remove(s);
            LaptopConstant.filePathMap.remove(s);
            LaptopConstant.videoIndex.remove(s);
            LaptopConstant.fileIndexCache.remove(s);
            LaptopConstant.secondIndexCache.invalidate(s);
            LaptopConstant.dataTableCache.invalidate(s);
            LaptopConstant.pointerAndConVer.remove(s);
            LaptopConstant.offsetMap.remove(s);
            LaptopConstant.clientVersionMap.remove(s);
            LaptopConstant.idsname_filePath.remove(s);

        }
        log.info("清除后timeMap" + LaptopConstant.timeMap);
        log.info("清除后infoMap" + LaptopConstant.infoMap);


    }
}
